/*
 *  $Id: Name.cs 1183 2010-11-10 17:04:21Z thenn.erannor $
 *	This file is a part of Ragima CCG.
 *	(C) 2008-2010 Ragima development group.
 *
 *	Licensed under the terms of the GNU GPL License version 2.
 *
 */

using System;

using Nereal.Serialization;

namespace Ragima.Languages {
    /// <summary>
    /// Падежи английского языка.
    /// </summary>
    public enum EnglishCase {
        Nominative,
        Possessive
    }

    /// <summary>
    /// Слово (имя) на английском языке.
    /// </summary>
    [ResourceLang("en"), ConstructorParameters("Nominative")]
    public sealed class EnglishName : LocalizedName {
        private string _name, _possessive;

        public EnglishName(string name) {
            _name = name;
            UpdatePossessive();
        }

        /// <summary>
        /// Имя в именителььном падеже.
        /// </summary>
        [XmlName("n")]
        public override string Nominative {
            get { return _name; }
        }

        /// <summary>
        /// Имя в притяжательном падеже.
        /// </summary>
        public string Possessive {
            get { return _possessive; }
        }

        /// <summary>
        /// Имя по падежу.
        /// </summary>
        public string this[EnglishCase c] {
            get {
                switch (c) {
                    case EnglishCase.Nominative: return _name;
                    case EnglishCase.Possessive: return _possessive;
                    default: return string.Empty;
                }
            }
        }

        /// <summary>
        /// Обновляет имя в притяжательном падеже.
        /// </summary>
        private void UpdatePossessive() {
            if (string.IsNullOrEmpty(_name)) {
                _possessive = string.Empty;
                return;
            }
            string ending = _name.EndsWith("s", StringComparison.CurrentCultureIgnoreCase) ? "'" : "'s";
            _possessive = _name + ending;
        }

        /// <summary>
        /// Создает ресурс английского имени.
        /// </summary>
        public static ResourceItem New(string id, string name) { return new ResourceItem(id, new EnglishName(name)); }
    }
}
